﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.SqlClient;
using DAL.Entities;

namespace DAL.Entities_DAL
{
    public class BGDichvu_DAL: BaseDAL, UTL.IBaseDAL
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            var sql = @" select * from BG_DICH_VU";
            return ExecuteQuery(sql);
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            string sql = @"DELETE FROM BG_DICH_VU WHERE MA_BGDV = '{0}'";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (BGDichvu)obj;
            string sql = @"INSERT INTO BG_DICH_VU(MA_BGDV, TEN_DV, DON_GIA) VALUES('{0}',N'{1}', '{2}') ";
            sql = string.Format(sql, o.MA_BGDV, o.TEN_DV, o.DON_GIA);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (BGDichvu)obj;
            string sql = @"SET dateformat dmy; UPDATE BG_DICH_VU SET TEN_DV=N'{1}', DON_GIA=N'{2}' WHERE MA_BGDV='{0}'";
            sql = string.Format(sql, o.MA_BGDV, o.TEN_DV, o.DON_GIA);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            throw new NotImplementedException();
        }
        //tim ma so max
        public DataTable Select_max()
        {
            var sql = @"SELECT MAX(MA_BGDV) AS id FROM BG_DICH_VU";
            return ExecuteQuery(sql);
        }
    }
}
